<?php 
	

	//echo json_encode($_FILES["file"]);
	header("Content-Type: text/html;charset=utf-8");

	$username = $_POST["username"];
	$tel =  $_POST["tel"];
	$email = $_POST["email"];
	$password = $_POST["password"];$password = md5($password);
	$headimg = $_POST['headimg']; //获取存放在临时的路径

	$filName = basename($headimg); //返回路径中的文件名部分

	$upload = "upload/";
	
	copy($headimg, $upload . $filName);  //拷贝到新目录

	$headimg = "upload/" . $filName;

	$conn = new mysqli("localhost", "root", "456789", "mysqlstudy");
	if($conn -> connect_error){
		die("连接失败：". $conn -> connect_error);
	}
	mysqli_query($conn, "set names utf8");

	date_default_timezone_set("Asia/Shanghai"); //设置默认时区

	$regTime = gettimeofday(); //返回当前时间
	$regTime = $regTime["sec"]; //Unix纪元以来的秒

	//echo date("Y-m-d H:i:s", $regTime); 格式化本地日期和时间

	$sql = "INSERT INTO tp_user_info (username, tel_phone, email, password, reg_time, headimg) VALUES ('$username', '$tel', '$email', '$password', '$regTime', '$headimg')";

	if($conn->query($sql) === TRUE){
		echo "添加成功！";
	}else{
		echo "Error: " . $sql . "<br>" . $conn->error;
	}


	
?>